﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Resources;
using System.Linq;
using System.Text;
using EffiProz.Core.Resources;

namespace EffiProz.Core.Lib.Tar
{
    public class RB
    {
        private static int keyCounter = 0;
        public static int DBBACKUP_SYNTAX = keyCounter++;
        public static int DBBACKUP_SYNTAXERR = keyCounter++;
        public static int TARGENERATOR_SYNTAX = keyCounter++;
        public static int PAD_BLOCK_WRITE = keyCounter++;
        public static int CLEANUP_RMFAIL = keyCounter++;
        public static int TARREADER_SYNTAX = keyCounter++;
        public static int UNSUPPORTED_ENTRY_PRESENT = keyCounter++;
        public static int BPR_WRITE = keyCounter++;
        public static int STREAM_BUFFER_REPORT = keyCounter++;
        public static int WRITE_QUEUE_REPORT = keyCounter++;
        public static int FILE_MISSING = keyCounter++;
        public static int MODIFIED_PROPERTY = keyCounter++;
        public static int FILE_DISAPPEARED = keyCounter++;
        public static int FILE_CHANGED = keyCounter++;
        public static int FILE_APPEARED = keyCounter++;
        public static int PIF_MALFORMAT = keyCounter++;
        public static int PIF_MALFORMAT_SIZE = keyCounter++;
        public static int ZERO_WRITE = keyCounter++;
        public static int PIF_TOOBIG = keyCounter++;
        public static int READ_DENIED = keyCounter++;
        public static int COMPRESSION_UNKNOWN = keyCounter++;
        public static int INSUFFICIENT_READ = keyCounter++;
        public static int DECOMPRESS_RANOUT = keyCounter++;
        public static int MOVE_WORK_FILE = keyCounter++;
        public static int CANT_OVERWRITE = keyCounter++;
        public static int CANT_WRITE_DIR = keyCounter++;
        public static int NO_PARENT_DIR = keyCounter++;
        public static int BAD_BLOCK_WRITE_LEN = keyCounter++;
        public static int ILLEGAL_BLOCK_BOUNDARY = keyCounter++;
        public static int WORKFILE_DELETE_FAIL = keyCounter++;
        public static int UNSUPPORTED_EXT = keyCounter++;
        public static int DEST_EXISTS = keyCounter++;
        public static int PARENT_NOT_DIR = keyCounter++;
        public static int CANT_WRITE_PARENT = keyCounter++;
        public static int PARENT_CREATE_FAIL = keyCounter++;
        public static int TAR_FIELD_TOOBIG = keyCounter++;
        public static int MISSING_SUPP_PATH = keyCounter++;
        public static int NONFILE_ENTRY = keyCounter++;
        public static int READ_LT_1 = keyCounter++;
        public static int DATA_CHANGED = keyCounter++;
        public static int UNEXPECTED_HEADER_KEY = keyCounter++;
        public static int TARREADER_SYNTAXERR = keyCounter++;
        public static int UNSUPPORTED_MODE = keyCounter++;
        public static int DIR_X_CONFLICT = keyCounter++;
        public static int PIF_UNKNOWN_DATASIZE = keyCounter++;
        public static int PIF_DATA_TOOBIG = keyCounter++;
        public static int DATA_SIZE_UNKNOWN = keyCounter++;
        public static int EXTRACTION_EXISTS = keyCounter++;
        public static int EXTRACTION_EXISTS_NOTFILE = keyCounter++;
        public static int EXTRACTION_PARENT_NOT_DIR = keyCounter++;
        public static int EXTRACTION_PARENT_NOT_WRITABLE = keyCounter++;
        public static int EXTRACTION_PARENT_MKFAIL = keyCounter++;
        public static int WRITE_COUNT_MISMATCH = keyCounter++;
        public static int HEADER_FIELD_MISSING = keyCounter++;
        public static int CHECKSUM_MISMATCH = keyCounter++;
        public static int CREATE_ONLY_NORMAL = keyCounter++;
        public static int BAD_HEADER_VALUE = keyCounter++;
        public static int BAD_NUMERIC_HEADER_VALUE = keyCounter++;
        public static int LISTING_FORMAT = keyCounter++;

        private static Object[] memberKeyArray = new Object[] {
        /* With Java 5, can use auto-boxing and get rid of all of the
         * Integer instantiations below.*/
       (DBBACKUP_SYNTAX), "DbBackup.syntax",
       (DBBACKUP_SYNTAXERR), "DbBackup.syntaxerr",
       (TARGENERATOR_SYNTAX), "TarGenerator.syntax",
       (PAD_BLOCK_WRITE), "pad.block.write",
       (CLEANUP_RMFAIL), "cleanup.rmfail",
       (TARREADER_SYNTAX), "TarReader.syntax",
       (UNSUPPORTED_ENTRY_PRESENT), "unsupported.entry.present",
       (BPR_WRITE), "bpr.write",
       (STREAM_BUFFER_REPORT), "stream.buffer.report",
       (WRITE_QUEUE_REPORT), "write.queue.report",
       (FILE_MISSING), "file.missing",
       (MODIFIED_PROPERTY), "modified.property",
       (FILE_DISAPPEARED), "file.disappeared",
       (FILE_CHANGED), "file.changed",
       (FILE_APPEARED), "file.appeared",
       (PIF_MALFORMAT), "pif.malformat",
       (PIF_MALFORMAT_SIZE), "pif.malformat.size",
       (ZERO_WRITE), "zero.write",
       (PIF_TOOBIG), "pif.toobig",
       (READ_DENIED), "read.denied",
       (COMPRESSION_UNKNOWN), "compression.unknown",
       (INSUFFICIENT_READ), "insufficient.read",
       (DECOMPRESS_RANOUT), "decompression.ranout",
       (MOVE_WORK_FILE), "move.work.file",
       (CANT_OVERWRITE), "cant.overwrite",
       (CANT_WRITE_DIR), "cant.write.dir",
       (NO_PARENT_DIR), "no.parent.dir",
       (BAD_BLOCK_WRITE_LEN), "bad.block.write.len",
       (ILLEGAL_BLOCK_BOUNDARY), "illegal.block.boundary",
       (WORKFILE_DELETE_FAIL), "workfile.delete.fail",
       (UNSUPPORTED_EXT), "unsupported.ext",
       (DEST_EXISTS), "dest.exists",
       (PARENT_NOT_DIR), "parent.not.dir",
       (CANT_WRITE_PARENT), "cant.write.parent",
       (PARENT_CREATE_FAIL), "parent.create.fail",
       (TAR_FIELD_TOOBIG), "tar.field.toobig",
       (MISSING_SUPP_PATH), "missing.supp.path",
       (NONFILE_ENTRY), "nonfile.entry",
       (READ_LT_1), "read.lt.1",
       (DATA_CHANGED), "data.changed",
       (UNEXPECTED_HEADER_KEY), "unexpected.header.key",
       (TARREADER_SYNTAXERR), "tarreader.syntaxerr",
       (UNSUPPORTED_MODE), "unsupported.mode",
       (DIR_X_CONFLICT), "dir.x.conflict",
       (PIF_UNKNOWN_DATASIZE), "pif.unknown.datasize",
       (PIF_DATA_TOOBIG), "pif.data.toobig",
       (DATA_SIZE_UNKNOWN), "data.size.unknown",
       (EXTRACTION_EXISTS), "extraction.exists",
       (EXTRACTION_EXISTS_NOTFILE), "extraction.exists.notfile",
       (EXTRACTION_PARENT_NOT_DIR), "extraction.parent.not.dir",
       (EXTRACTION_PARENT_NOT_WRITABLE), "extraction.parent.not.writable",
       (EXTRACTION_PARENT_MKFAIL), "extraction.parent.mkfail",
       (WRITE_COUNT_MISMATCH), "write.count.mismatch",
       (HEADER_FIELD_MISSING), "header.field.missing",
       (CHECKSUM_MISMATCH), "checksum.mismatch",
       (CREATE_ONLY_NORMAL), "create.only.normal",
       (BAD_HEADER_VALUE), "bad.header.value",
       (BAD_NUMERIC_HEADER_VALUE), "bad.numeric.header.value",
       (LISTING_FORMAT), "listing.format",
    };

        private HashMap keyIdToString = new HashMap();

        protected HashMap getKeyIdToString()
        {
            return keyIdToString;
        }


        public RB()
        {
           if (memberKeyArray == null)
                throw new Exception("'static memberKeyArray not set");
            for (int i = 0; i < memberKeyArray.Length; i += 2)
            {
                keyIdToString.put(memberKeyArray[i], memberKeyArray[i + 1]);
            }          
        }       
     

        // The following methods are a passthru wrappers for the wrapped RCPRB.

        /** @see RefCapablePropertyResourceBundle#getString(String) */
        public String getString(int id)
        {
            return (String)getKeyIdToString().get((id));
        }

        /** @see RefCapablePropertyResourceBundle#getString(String, String[], int) */
        public String getString(int id, String[] sa)
        {
            return (String)getKeyIdToString().get((id));
        }

        /** @see RefCapablePropertyResourceBundle#getExpandedString(String, int) */
        public String getExpandedString(int id)
        {
            return (String)getKeyIdToString().get((id));
        }

        /** @see RefCapablePropertyResourceBundle#getExpandedString(String, String[], int, int) */
        public String getExpandedString(int id, String[] sa)
        {
            return "Tar Error";
        }

        /* IMPORTANT:  Leave the singleton instantiation at the end here!
         * Otherwise there will be a confusing tangle between clinitting and
         * singleton instantiation.  */
        static public RB singleton = new RB();

        /* Convenience wrappers follow for getString(int, String[]) for up to
    * 3 int and/or String positionals.  Java 5 variable-length parameters
    * can eliminate the repetition here, plus generalize to random
    * numbers of parameters. */
        public String getString(int id, String s1)
        {
            return getString(id, new String[] { s1 });
        }
        public String getString(int id, String s1, String s2)
        {
            return getString(id, new String[] { s1, s2 });
        }
        public String getString(int id, String s1, String s2, String s3)
        {
            return getString(id, new String[] { s1, s2, s3 });
        }
        public String getString(int id, String s1, String s2, String s3, String s4)
        {
            return getString(id, new String[] { s1, s2, s3, s4 });
        }
        public String getString(int id, int i1)
        {
            return getString(id, new String[] { i1.ToString() });
        }
        public String getString(int id, int i1, int i2)
        {
            return getString(id, new String[] {
            (i1).ToString(), i2.ToString()
        });
        }
        public String getString(int id, int i1, int i2, int i3)
        {
            return getString(id, new String[] {
            (i1).ToString(), (i2).ToString(),(i3).ToString()
        });
        }
        public String getString(int id, int i1, String s2)
        {
            return getString(id, new String[] {
            (i1).ToString(), s2
        });
        }
        public String getString(int id, String s1, int i2)
        {
            return getString(id, new String[] {
            s1,(i2).ToString()
        });
        }

        public String getString(int id, int i1, int i2, String s3)
        {
            return getString(id, new String[] {
            (i1).ToString(), (i2).ToString(), s3
        });
        }
        public String getString(int id, int i1, String s2, int i3)
        {
            return getString(id, new String[] {
           (i1).ToString(), s2, (i3).ToString()
        });
        }
        public String getString(int id, String s1, int i2, int i3)
        {
            return getString(id, new String[] {
            s1, (i2).ToString(), (i3).ToString()
        });
        }
        public String getString(int id, int i1, String s2, String s3)
        {
            return getString(id, new String[] {
            (i1).ToString(), s2, s3
        });
        }
        public String getString(int id, String s1, String s2, int i3)
        {
            return getString(id, new String[] {
            s1, s2, (i3).ToString()
        });
        }
        public String getString(int id, String s1, int i2, String s3)
        {
            return getString(id, new String[] {
            s1, (i2).ToString(), s3
        });
        }

    }
}
